package LoginPackage;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import PagePackage.MyPageFactory;
import PagePackage.internalPageClass;
import PagePackage.loginPageClass;
import PagePackage.userContactInfoPageClass;
import PagePackage.userRolePageClass;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.testng.AssertJUnit.*;
import PagePackage.usersPageClass;

public class LockedUser extends TestBaseClass {

	
	
	@Test (priority=0)
	 public void AdminUnlocksUser() {
		goToMainPage();
		checkPage()
		.loginAs(adminEmail, adminPassword)
		.clickusertab()
		.findUserByEmail(lockedUser)
		.scrollAndClick(0, 0, "//*[text()='"+lockedUser+"']")
		.getTextNotification()
		.lockUnlock()
		.findUserByEmail(lockedUser)
		.scrollAndClick(0, 0, "//*[text()='"+lockedUser+"']")
		.notificationAbsents()
		.logout()
		.loginAs(lockedUser, lockedUserPassword)
		.logout();
		
}
	@Test (priority=1)
	 public void SAUnlocksUser() {
		goToMainPage();
		checkPage()
		.loginAs(saEmail, saPassword)
		.clickusertab()
		.findUserByEmail(SAlockedUser)
		.scrollAndClick(0, 0, "//*[text()='"+SAlockedUser+"']")
		.getTextNotification()
		.lockUnlock()
		.findUserByEmail(SAlockedUser)
		.scrollAndClick(0, 0, "//*[text()='"+SAlockedUser+"']")
		.notificationAbsents()
		.logout()
		.loginAs(SAlockedUser, SAlockedUserPassword)
		.logout();
	
	
	
}
	@Test (priority=2)
	 public void AdminUnlocksAdmin() {
		goToMainPage();
		checkPage()
		.loginAs(adminEmail, adminPassword)
		.clickusertab()
		.findUserByEmail(lockedAdmin)
		.scrollAndClick(0, 0, "//*[text()='"+lockedAdmin+"']")
		.getTextNotification(); 
		MyPageFactory.getPage(driver, userContactInfoPageClass.class).lockButton.getAttribute("disabled");
		MyPageFactory.getPage(driver, internalPageClass.class).logout();
	
		
}
	@Test (priority=3)
	 public void SAUnlocksAdmin() {
		goToMainPage();
		checkPage()
		.loginAs(saEmail, saPassword)
		.clickusertab()
		.findUserByEmail(SAlockedAdmin)
		.scrollAndClick(0, 0, "//*[text()='"+SAlockedAdmin+"']")
		.getTextNotification()
		.lockUnlock()
		.findUserByEmail(SAlockedAdmin)
		.scrollAndClick(0, 0, "//*[text()='"+SAlockedAdmin+"']");
		driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
		MyPageFactory.getPage(driver, userContactInfoPageClass.class).notificationAbsents()
		.logout();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(SAlockedAdmin, SAlockedAdminPassword)
		.logout();
	
	
	
	}
	
	@Test (priority=4)
	public void AdminUnlocksSA() {
		goToMainPage();
		checkPage()
		.loginAs(adminEmail, adminPassword)
		.clickusertab()
		.findUserByEmail(lockedSA)
		.scrollAndClick(0, 0, "//*[text()='"+lockedSA+"']")
		.getTextNotification(); 
		MyPageFactory.getPage(driver, userContactInfoPageClass.class).lockButton.getAttribute("disabled");
		MyPageFactory.getPage(driver, internalPageClass.class).logout();
	
	}
	@Test (priority=5)
	 public void SAUnlocksSA() {
		goToMainPage();
		checkPage()
		.loginAs(saEmail, saPassword)
		.clickusertab()
		.findUserByEmail(lockedSA)
		.scrollAndClick(0, 0, "//*[text()='"+lockedSA+"']")
		.getTextNotification()
		.lockUnlock()
		.findUserByEmail(lockedSA)
		.scrollAndClick(0, 0, "//*[text()='"+lockedSA+"']");
		driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
		MyPageFactory.getPage(driver, userContactInfoPageClass.class).notificationAbsents()
		.logout();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(lockedSA, lockedSAPassword)
		.logout();
	
}

}
